package com.itheima.dao;

import com.itheima.domian.Member;
import com.itheima.domian.Orders;
import com.itheima.domian.Product;
import com.itheima.domian.Traveller;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

public interface IOrdersDao {

    @Select("select * from Orders")
    @Results({
            @Result(id = true ,property = "id",column = "id"),
            @Result(property = "orderNum",column = "orderNum"),
            @Result(property = "orderTime",column = "orderTime"),
            @Result(property = "orderStatus",column = "orderStatus"),
            @Result(property = "peopleCount",column = "peopleCount"),
            @Result(property = "payType",column = "payType"),
            @Result(property = "orderDesc",column = "orderDesc"),
            @Result(property = "product",column = "productId",javaType = Product.class,one = @One(select = "com.itheima.dao.IProductDao.findById"))
     })
    public List<Orders> findAll() throws Exception;


    //多表操作
    @Select("select * from Orders where id = #{id}")
    @Results({
            @Result(id = true ,property = "id",column = "id"),
            @Result(property = "orderNum",column = "orderNum"),
            @Result(property = "orderTime",column = "orderTime"),
            @Result(property = "orderStatus",column = "orderStatus"),
            @Result(property = "peopleCount",column = "peopleCount"),
            @Result(property = "payType",column = "payType"),
            @Result(property = "orderDesc",column = "orderDesc"),
            @Result(property = "product",column = "productId",javaType = Product.class,one = @One(select = "com.itheima.dao.IProductDao.findById")),
            @Result(property = "member",column = "memberId",javaType = Member.class,one = @One(select = "com.itheima.dao.IMemberDao.findById")),
            @Result(property = "travellers",column = "id" ,javaType = java.util.List.class , many =  @Many(select = "com.itheima.dao.ITravellersDao.findByOrdersId"))
    })
    Orders findByid(String id) throws Exception;
}
